using UnityEngine;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using DG.Tweening;

[TaskCategory("MyTools")]
public class DotweenMoveAction : Action
{
    public SharedGameObject self;
    public SharedVector3 targetPoint;
    public SharedFloat speed;
    private TaskStatus taskStatus;
    private Tweener tweener;
    public SharedBool isWait;
    public override void OnStart()
    {
        this.taskStatus = TaskStatus.Running;
        if (this.isWait.Value)
        {
            this.tweener = this.self.Value.transform.DOMove(this.targetPoint.Value, this.speed.Value).SetSpeedBased().SetEase(Ease.Linear).OnComplete(() =>
            {
                this.taskStatus = TaskStatus.Success;
            });
        }
        else
        {
            this.tweener = this.self.Value.transform.DOMove(this.targetPoint.Value, this.speed.Value).SetSpeedBased().SetEase(Ease.Linear);
            this.taskStatus = TaskStatus.Success;
        }
    }

    public override TaskStatus OnUpdate()
    {
        return this.taskStatus;
    }
}